package valerij_timakov.home_finances.logic;

import java.util.Map;

import valerij_timakov.home_finances.data.finances.AccountItem;
import valerij_timakov.home_finances.exceptions.AppExceptionWrongState;
import valerij_timakov.home_finances.exceptions.AppPersProviderException;
import valerij_timakov.home_finances.persistent.storages.finances.IAccountStorage;
import valerij_timakov.home_finances.utils.Utils;

public class AccountWorker {
	
	private IAccountStorage storage;
	
	public AccountWorker(IAccountStorage storage) throws AppExceptionWrongState {
		if (storage == null) {
			throw new AppExceptionWrongState("Не задан провайдер данных!");
		}
		this.storage = storage;
	}
	
	public Map<Long, AccountItem> getUserAccounts(long userId) throws AppPersProviderException, AppExceptionWrongState {
		return storage.getAccounts(userId);
	}
	
	public long[] getUserAccountsIds(long userId) throws AppPersProviderException, AppExceptionWrongState {
		return Utils.longCollectionToArray(storage.getAllUserAccounts(userId).keySet());
	}
}
